// JavaScript Document
var Info = function(){
	var Info = function(){
		this.gist = null;
		this.main = null;
		this.ballName = "round";
		this.left = null;
		this.top = null;
	}
	Info.prototype = {
		showAll:function(obj){
			var self = this;
			self.main = document.getElementById("mcinfo");
			self.showGist(obj);
			//生成屏蔽层
			alphaHandle('');			
			
			with(self.main.style){
				if(x>1275-550){
					left = self.left - 510-55 +'px'; 
					with(self.section.style){
						left = self.left-500 -196-55 +'px'; 
					}
				}
				else{
					left = self.left + 141 + "px";
				}
				top = self.top + "px";
				display = "";	
			}
			//点击气泡后通过myajax获取气泡的详细信息
			var myajax = getByAjax();
			myajax.init(null,"get",true);
			myajax.get("/networkforum/garden/ball_info.do?articleId="+obj.articleId,function(d){
				//数据展示
				var a = new Array();
//				a.push(eval("("+d+")"));
				a.push(toJson(d));
				activeInfo().addNode(a);	
			});
					
		},
		showGist:function(obj){
			//gist的width,height为写死的数据，修改须在garden_main.css中更改
			//width:165,height:190
			var self = this;
			self.section = document.getElementById("ballInfo");
			self.left = obj.offsetLeft+obj.offsetWidth;				
			self.top = obj.offsetTop + obj.offsetHeight;				
			
			document.getElementById("createTime").innerHTML = obj.createTime;
			document.getElementById("replyTimes").innerHTML = obj.replyTimes;
			document.getElementById("visitTimes").innerHTML = obj.visitTimes;
			document.getElementById("userName").innerHTML = obj.userName;
			document.getElementById("userPhoto").src = obj.userPhoto;

			with(self.section.style){
				if(x>1275-186-55){
					left = self.left -186-50 +'px'; 
				}
				else{
					left = self.left-45 + "px";
				}
				top = self.top + "px";
				display = '';
			}
		},
		hiddenGist:function(){
			var self = this;
			self.section.style.display = 'none';
		},
		hiddenAll:function(){
			var self = this;
			self.hiddenGist();
			self.main.style.display = "none";
			alphaHandle('none');
		},
		create:function(cid){
			return document.createElement(cid);
		},
		css:function(node,css){
			node.style.cssText = node.style.cssText + css;
		}
	}	
	return new Info();
}();
//点击创建气泡onclick事件
function addBall(obj,kind){
	document.getElementById("useractive").value = "";
	var ballKind = document.getElementById("ballKind");
	var ballSign = document.getElementById("ballSign");
	ballKind.innerHTML = kind;
	ballSign.src = obj.src;
	ballHandle("");
}
function ballHandle(dis){
	scrollInit();
	var inner = document.getElementById("inner");
	inner.style.display = dis;
	alphaHandle(dis);
	scrollsTo();
}
function alphaHandle (dis){
	var alpha = document.getElementById("addBall");
	alpha.style.display = dis;	
}
function createBall(){
	var area = document.getElementById("useractive");
	//var update = document.getElementById("update");
	//var showInfo = document.getElementById("showInfo");
	//var level = document.getElementById("level");
	//var time = document.getElementById("time");
	var input = document.getElementsByTagName('input');
	var ballKind = document.getElementById("ballKind");
	var arr = new Array();
	arr.push(encodeURIComponent(area.value));
	arr.push(encodeURIComponent(ballKind.innerHTML));
	for(var i=0;i<input.length;i++){
		/*if(input[i].id = "update"&&input[i].checked){
			arr.push(input[i].value);
		}
		else if(input[i].id == "showInfo"&&input[i].checked){
			arr.push(input[i].value);
		}*/
		if(input[i].id == "level"&&input[i].checked){
			arr.push(input[i].value);		
		}
		/*else if(input[i].id == "time"&&input[i].checked){
			arr.push(input[i].value);
		}*/
	}
	//创建新的气泡
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/garden/create_ball.do?ballInfo="+arr,function(d){
		ballHandle("none");
//		garden.createBall(eval("("+d+")"));
		garden.createBall(toJson(d));
	});
	myajax = null;
}
function searchBall(){
	index = 0;
	size = 30;
	var kind = "";
	var scope = "";
	var publishTime = document.getElementById("control_date").value;
	var input = document.getElementsByClassName("_ball");
	for(var i=0;i<input.length;i++){
		if(input[i].id == "kind"&&input[i].checked){
			kind = input[i].value;
		}
		else if(input[i].id == "scope"&&input[i].checked){
			scope = input[i].value;
		}
	}
	url = "/networkforum/garden/load_garden.do?ballKind="+encodeURIComponent(kind)+
	  "&userRelation="+scope+"&publishTime="+publishTime;
	//创建新的气泡
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get(url+"&index="+index+"&size="+size,function(d){
		clearGarden();
		var data = toJson(d);
		if(data.length==0){
			alert("无更多信息");
			return;
		}
		garden.init(data);
	});
	myajax = null;
}
function clearGarden(){
	var garden = document.getElementById("garden");
	garden.innerHTML = null;
}
function reloadInfo(inde){
	if(index ==0&&inde<0){
		return;
	}
	index = index+inde;
	//url = url + "?index="+index+"&size="+size;
	//创建新的气泡
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get(url+"&index="+index+"&size="+size,function(d){
		clearGarden();
		var data = toJson(d);
		if(data.length==0){
			alert("无更多信息");
			return;
		}
		garden.init(data);
	});
	myajax = null;
}
//重写系统默认方法
var x = null;
var y = null;
document.onmousemove = function(ev){
	ev = ev || window.event; 
	x = ev.clientX;
	y = ev.clientY;
	if(y<80){
		header.style.height = 160 +"px";
	}
	else if(y>190){
		header.style.height = 0 +"px";
	}
	if(!searchSection)return;
	if(x<3){
		searchSection.style.width = 190 + "px";
	}
	if(x>300){
		searchSection.style.width = 0 + "px";
	}
}


